﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.ApplicationBlocks.Data;
using System.Data;
using System.Data.SqlClient;

namespace MyTemplate
{
    public partial class ArticleList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["UserName"] != null)
            {
                Label1.Visible = false;
                //string query = "Select * from tbArticles ";
                //string filterText = txtFilter.Text.TrimStart().TrimEnd();
                //if (filterText.Equals(""))
                //{
                //    query += ";";
                //}
                //else
                //{
                //    query += " where Title like '%'+@filterText+'%' ;";
                //}

                //SqlConnection connection = new SqlConnection(SqlHelper.DbConnectionString);
                //SqlCommand command = null;
                //SqlDataReader reader = null;

                //connection.Open();
                //command = new SqlCommand(query, connection);
                //command.Parameters.Add("@filterText", SqlDbType.VarChar);
                //command.Parameters["@filterText"].Value = filterText;
                //reader = command.ExecuteReader();

                //GridView1.DataSource = reader;
                //GridView1.DataBind();
                //connection.Close();
                ArticleManager am = new ArticleManager();
                GridView1.DataSource = am.getArticles(txtFilter.Text.TrimStart().TrimEnd());
                GridView1.DataBind();
            }
            else
            {
                GridView1.Visible = false;
                Label1.Text = "로그인 후 이용하실 수 있습니다";
            }
        }
    }
}